package flc.ast.dialog;

import android.content.Context;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.lxj.xpopup.core.AttachPopupView;

import flc.ast.R;
import stark.common.basic.utils.MediaUtil;

public class PlayInfoDialog extends AttachPopupView {
    private String videoPath;
    private TextView tvFileName;
    private TextView tvLocation;
    private TextView tvSize;
    private TextView tvCreateTime;
    private TextView tvFormat;
    private TextView tvResolution;
    private TextView tvDuration;


    public PlayInfoDialog(@NonNull Context context, String videoPath) {
        super(context);
        this.videoPath = videoPath;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_play_info;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        tvFileName = (TextView) findViewById(R.id.tvFileName);
        tvLocation = (TextView) findViewById(R.id.tvLocation);
        tvSize = (TextView) findViewById(R.id.tvSize);
        tvCreateTime = (TextView) findViewById(R.id.tvCreateTime);
        tvFormat = (TextView) findViewById(R.id.tvFormat);
        tvResolution = (TextView) findViewById(R.id.tvResolution);
        tvDuration = (TextView) findViewById(R.id.tvDuration);

        tvLocation.setSelected(true);
        tvFileName.setText(FileUtils.getFileName(videoPath));
        tvLocation.setText(videoPath);
        tvSize.setText(FileUtils.getSize(videoPath));
        tvCreateTime.setText(TimeUtils.millis2String(FileUtils.getFileLastModified(videoPath), "yyyy年MM月dd日 HH:mm:ss"));
        tvFormat.setText(FileUtils.getFileName(videoPath).substring(FileUtils.getFileName(videoPath).lastIndexOf(".") + 1));
        tvResolution.setText(MediaUtil.getMediaMetadataInfo(videoPath).getWidth() + " x " + MediaUtil.getMediaMetadataInfo(videoPath).getHeight());
        tvDuration.setText(TimeUtils.millis2String(MediaUtil.getDuration(videoPath), "mm:ss"));
    }


}
